using System;
using System.Globalization;
using System.Reflection.Emit;
using RaisingStudio.SmallBasicCompiler.Completion;

namespace RaisingStudio.SmallBasicCompiler.Statements
{
    public class GotoStatement : Statement
    {
        public TokenInfo GotoToken;
        public TokenInfo Label;
        public override void EmitIL(CodeGenScope scope)
        {
            Label label = scope.Labels[this.Label.NormalizedText];
            scope.ILGenerator.Emit(OpCodes.Br, label);
        }
        public override void PopulateCompletionItems(CompletionBag completionBag, int line, int column, bool globalScope)
        {
            if (this.Label.Token == Token.Illegal || column < this.Label.Column)
            {
                CompletionHelper.FillAllGlobalItems(completionBag, globalScope);
                return;
            }
            CompletionHelper.FillLabels(completionBag);
        }
        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentUICulture, "{0} {1}\r\n", new object[]
			{
				this.GotoToken.Text, 
				this.Label.Text
			});
        }
    }
}
